package com.edu.bean;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Teacher {

    @Value("1")
    private int id;

    @Value("张三")
    private String name;

    @Value("男")
    private String sex;

    @Value("25")
    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 等效于
     *  init-method= "myInit"
     */
    @PostConstruct
    public void myInit(){
        this.id = 2;
        this.name = "淑芬";
        this.sex = "女";
        this.age = 24;
    }

    @PreDestroy
    public void myDestroy(){
        System.out.println("执行了 自定义的销毁方法");
    }
}
